<template>
  <div>
    <el-card
      class="box-card"
      v-loading="loading"
      element-loading-text="正在导出中"
      element-loading-spinner="el-icon-loading"
    >
      <div class="block">
        <div class="nav">
          <el-select v-model="form.student_year" placeholder="请选择年级">
            <el-option
              v-for="item in optionss"
              :key="item.specialized"
              :label="item.specialized"
              :value="item.specialized"
              @click.native="getClass()"
            >
            </el-option>
          </el-select>
          <el-select v-model="form.student_class" placeholder="请选择班级">
            <el-option
              v-for="item in options2"
              :key="item.class"
              :label="item.class"
              :value="item.class"
            >
            </el-option>
          </el-select>
          <el-select
            v-model="form.experiment_name"
            placeholder="请选择实验名称"
          >
            <el-option
              v-for="item in options1"
              :key="item.name"
              :label="item.name"
              :value="item.name"
            >
            </el-option>
          </el-select>
          <el-button type="primary" @click="chaxun()" class="btn">
            查询
          </el-button>
          <el-button type="primary" @click="excel()" class="btns">
            导出Excel
          </el-button>
          <!-- <el-button type="primary" @click="alles()" class="btns">
            导出全部
          </el-button> -->
        </div>
        <el-table
          :data="
            tableData.slice(
              (currentPage - 1) * pageSize,
              currentPage * pageSize
            )
          "
          style="width: 100%"
          border
          stripe
          class="tablr"
        >
          <el-table-column prop="student_class" label="班级"> </el-table-column>
          <el-table-column prop="student_num" label="学号"> </el-table-column>
          <el-table-column prop="student_name" label="姓名"> </el-table-column>
          <el-table-column prop="experiment" label="实验"></el-table-column>
          <el-table-column
            prop="grade"
            label="分数"
            width="60"
            align="center"
          ></el-table-column>

          <!-- 操作-旧 -->
          <!-- <el-table-column prop="js" label="操作" align="center">
            <template slot-scope="scope">
              <el-button
                type="danger"
                size="mini"
                v-if="scope.row.postate == '1'"
                @click="dialog(scope.row.id)"
              >
                批阅
              </el-button>
              <el-tag
                type="success"
                v-if="scope.row.postate == '0' && scope.row.state == 2"
              >
                已批阅
              </el-tag>
              <el-tag
                type="success"
                v-if="scope.row.postate == '2' && scope.row.state == 2"
              >
                已批阅
              </el-tag>
              <el-tag type="danger" v-if="scope.row.state == 1">未完成</el-tag>
            </template>
          </el-table-column> -->

          <!-- 操作-新 -->
          <el-table-column align="center" label="操作">
            <template slot-scope="scope">
              <el-button
                type="danger"
                size="mini"
                v-if="scope.row.poste == '0' && scope.row.poste == 0"
                @click="Teach_make(scope.row)"
              >
                打分
              </el-button>
              <el-button
                type="danger"
                size="mini"
                v-if="scope.row.poste == '1' && scope.row.poste == 1"
                disabled
              >
                已批阅
              </el-button>
            </template>
          </el-table-column>
          <el-table-column align="center" :scoped-slot="renderHeader">
            <!-- render-header会报element-ui警告 -->
            <!-- <el-table-column align="center" :render-header="renderHeader"> -->
            <template slot-scope="scope">
              <el-button type="primary" size="mini" @click="daochu(scope.row)">
                导出
              </el-button>
              <el-tag type="danger" v-if="scope.row.state == 1">未完成</el-tag>
            </template>
          </el-table-column>
        </el-table>

        <!-- 分页 -->
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[10]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.length"
        >
        </el-pagination>

        <!-- 霍尔打分 -->
        <el-dialog title="主观题" :visible.sync="changepop_huoer" width="50%">
          <el-row type="flex" justify="center">
            <img
              style="width: 25vw; margin-bottom: 20px"
              :src="zhuguan_input"
            />
          </el-row>
          <el-row type="flex" justify="center">
            <el-input
              placeholder="请输入分数"
              v-model="teacher_input"
              label-width="120px"
            >
            </el-input>
          </el-row>
          <el-row type="flex" justify="center">
            <el-button
              type="danger"
              @click="
                changepop_huoer = false;
                ChangeClose();
              "
              >退出</el-button
            >
            <el-button
              type="success"
              @click="
                changepop_huoer = false;
                tea_get(teacher_input);
              "
              >保存</el-button
            >
          </el-row>
        </el-dialog>
        <!-- 旧单摆打分 -->
        <el-dialog title="主观题" :visible.sync="changepop_danbai" width="50%">
          <el-row type="flex" justify="center">
            <img
              src="https://zj-cloudimg.oss-cn-chengdu.aliyuncs.com/img/202210101022233.png"
              style="height: 40px"
            />
            =
            <textarea
              placeholder="请输入记录评语..."
              v-model="danbai_input2"
              disabled
              class="shurukuang"
            >
            </textarea>
          </el-row>
          <el-row type="flex" justify="center">
            <el-input
              placeholder="请输入分数"
              v-model="bc_score"
              label-width="120px"
            >
            </el-input>
            <!-- <p>(保留两位有效数得分【分数范围0-4分】)</p> -->
            <p>(保留两位有效数【0-4分】)</p>
          </el-row>

          <el-row type="flex" justify="center">
            <img
              src="https://zj-cloudimg.oss-cn-chengdu.aliyuncs.com/img/202210101025175.png"
              style="height: 40px"
            />
            =
            <textarea
              placeholder="请输入记录评语..."
              v-model="danbai_input3"
              disabled
              class="shurukuang"
            >
            </textarea>
          </el-row>
          <el-row type="flex" justify="center">
            <el-input
              placeholder="请输入分数"
              v-model="zq2_score"
              label-width="120px"
            >
            </el-input>
            <!-- <p>(保留两位有效数得分【分数范围0-4分】)</p> -->
            <p>(保留两位有效数【0-4分】)</p>
          </el-row>
          <el-row type="flex" justify="center">
            <textarea
              placeholder="请输入记录评语..."
              v-model="danbai_input"
              disabled
            >
            </textarea>
          </el-row>
          <el-row type="flex" justify="center">
            <el-input
              placeholder="请输入分数"
              v-model="res_score"
              label-width="120px"
            >
            </el-input>
            <!-- <p>(周期平均值保留三位小数得分【分数范围0-30分】)</p> -->
            <p>(周期平均值保留三位小数【0-30分】)</p>
          </el-row>
          <el-row type="flex" justify="center">
            <el-button
              type="danger"
              @click="
                changepop_danbai = false;
                ChangeClose();
              "
              >退出</el-button
            >
            <el-button
              type="success"
              @click="
                changepop_danbai = false;
                tea_danbai(tgrade);
              "
              >保存</el-button
            >
          </el-row>
        </el-dialog>
        <!-- 欧姆表打分 -->
        <el-dialog title="主观题" :visible.sync="changepop_oumu" width="50%">
          <el-row type="flex" justify="center">
            <img style="width: 25vw; margin-bottom: 20px" :src="ZG1_input" />
          </el-row>
          <el-row type="flex" justify="center">
            <el-input
              placeholder="请输入分数"
              v-model="OuTea_input1"
              label-width="120px"
            >
            </el-input>
          </el-row>
          <el-row type="flex" justify="center">
            <img style="width: 25vw; margin-bottom: 20px" :src="ZG2_input" />
          </el-row>
          <el-row type="flex" justify="center">
            <el-input
              placeholder="请输入分数"
              v-model="OuTea_input2"
              label-width="120px"
            >
            </el-input>
          </el-row>
          <el-row type="flex" justify="center">
            <el-button
              type="danger"
              @click="
                changepop_oumu = false;
                ChangeClose();
              "
              >退出</el-button
            >
            <el-button
              type="success"
              @click="
                changepop_oumu = false;
                OuMuTeaGet(OuTea_input1, OuTea_input2);
              "
              >保存</el-button
            >
          </el-row>
        </el-dialog>

        <el-dialog title="审批" :visible.sync="dialogVisible" width="600px">
          <div class="toutou">
            <div class="photo">
              <p v-if="this.form.p1 && this.form.p2">表头测量数据截图</p>
              <p v-if="this.form.p1 && this.form.p2 == ''">X-曲线：</p>
              <img :src="this.form.p1" class="photos" />
            </div>

            <el-input
              placeholder="请输入分数"
              class="mark_input"
              v-model="form.fraction_p1"
            ></el-input>

            <div v-if="this.form.p2 != ''" class="tupian2">
              <div class="photo1">
                <p>实验电路设计截图</p>
                <img :src="this.form.p2" class="photos" />
              </div>

              <el-input
                placeholder="请输入分数"
                class="mark_input"
                v-model="form.fraction_p2"
              ></el-input>
            </div>
          </div>

          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogs">取 消</el-button>
            <el-button type="primary" @click="dialogs1">确 定</el-button>
          </div>
        </el-dialog>
      </div>
    </el-card>
  </div>
</template>
<script>
import JSZip from "jszip";
import FileSaver from "file-saver";
import axios from "axios";
export default {
  data() {
    return {
      // 主观题弹窗
      changepop_huoer: false,
      changepop_oumu: false,
      changepop_danbai: false,
      danbai_input: "",
      danbai_input2: "",
      danbai_input3: "",
      zhuguan_input: "",
      teacher_input: "",
      res_score: "",
      bc_score: "",
      zq2_score: "",
      tgrade: "",
      ZG1_input: "",
      ZG2_input: "",
      OuTea_input1: "",
      OuTea_input2: "",

      loading: false,
      currentPage: 1,
      pageSize: 10,
      dialogVisible: false,
      student_id: "",
      //  idNedd:faflse,
      tutu: false,
      form: {
        fraction_p1: "",
        fraction_p2: "",
        p1: "",
        p2: "",
        student_num: "",
        student_year: "",
        student_class: "",
        experiment_name: "",
      },
      // 三个空

      // 班级
      options2: [],
      optionss: [],
      options1: [],
      tableData: [],
      // 导出全部
      alls: [],
    };
  },
  created() {
    this.getGrade();

    this.getEXper_Name();
    // this.getmess();
  },
  watch: {
    $router: "getClass",
  },
  methods: {
    // 主观题打分
    // 得到年级
    Teach_make(val) {
      //console.log(val);
      if (val.experiment == "霍尔效应测量磁感应强度") {
        this.changepop_huoer = true;
      }
      if (val.experiment == "欧姆表的改装设计") {
        this.changepop_oumu = true;
      }
      if (val.experiment == "旧单摆法测重力加速度") {
        this.changepop_danbai = true;
      }
      this.zhuguan_input = val.tu;
      this.ZG1_input = val.p1;
      this.ZG2_input = val.p2;
      this.danbai_input = val.res;
      this.danbai_input2 = val.ave_bc;
      this.danbai_input3 = val.ave_zq2;
      var stu_id = val.student_num;
      sessionStorage.setItem("stu_id", stu_id);
    },
    ChangeClose() {
      (this.teacher_input = ""),
        (this.OuTea_input1 = ""),
        (this.OuTea_input2 = "");
    },
    // 教师打分保存
    async tea_get(val) {
      var stu_id = sessionStorage.getItem("stu_id");
      // 判断是否为数字
      // 霍尔打分
      // if (this.form.experiment_name == "霍尔效应测量磁感应强度") {
      //   if (val > 20 || val < 0) {
      //     this.$message.error("分数范围为0-20");
      //     this.ChangeClose();
      //     return;
      //   }
      //   const { data: res } = await this.$http.post(
      //     "http://180.76.111.200:3001/api/huoer/DaFen",
      //     {
      //       student_id: stu_id,
      //       gradetu: val,
      //     }
      //   );
      //   if (res.code == 200) {
      //     this.$message.success("评分成功！");
      //     this.chaxun();
      //   } else {
      //     this.$message.error("评分失败！");
      //     // this.ChangeClose();
      //   }
      // }
      if (this.form.experiment_name == "霍尔效应测量磁感应强度") {
        if (val > 20 || val < 0) {
          this.$message.error("分数范围为0-20");
          this.ChangeClose();
          return;
        }
        const { data: res } = await this.$http.post(
          "http://180.76.111.200:3001/api/huoer/DaFen",
          {
            student_id: stu_id,
            gradetu: val,
          }
        );
        if (res.code == 200) {
          this.$message.success("评分成功！");
          this.chaxun();
        } else {
          this.$message.error("评分失败！");
          this.ChangeClose();
        }
      }
    },
    // 单摆打分
    async tea_danbai() {
      var stu_id = sessionStorage.getItem("stu_id");
      // 判断是否为数字
      if (this.form.experiment_name == "旧单摆法测重力加速度") {
        if (this.bc_score > 4 || this.bc_score < 0 || this.bc_score == "") {
          this.changepop_danbai = true;
          this.$message.error("分数范围为0-4");
          this.ChangeClose();
          return;
        }
        if (this.zq2_score > 4 || this.zq2_score < 0 || this.zq2_score == "") {
          this.changepop_danbai = true;
          this.$message.error("分数范围为0-4");
          this.ChangeClose();
          return;
        }
        if (this.res_score > 30 || this.res_score < 0 || this.res_score == "") {
          this.changepop_danbai = true;
          this.$message.error("分数范围为0-30");
          this.ChangeClose();
          return;
        }
        const { data: res } = await this.$http.post(
          "http://180.76.111.200:3001/api/js2",
          {
            student_id: stu_id,
            bc_score: this.bc_score,
            zq2_score: this.zq2_score,
            res_score: this.res_score,
          }
        );
        if (res.code == 200) {
          this.$message.success("评分成功！");
          this.chaxun();
        } else {
          this.$message.error("评分失败！");
          this.ChangeClose();
        }
      }
    },
    // 欧姆打分
    async OuMuTeaGet(val1, val2) {
      var stu_id = sessionStorage.getItem("stu_id");
      // 判断是否为数字

      if (this.form.experiment_name == "欧姆表的改装设计") {
        if (val1 > 10 || val1 < 0) {
          this.$message.error("分数范围为0-10");
          this.ChangeClose();
          return;
        }
        if (val2 > 10 || val2 < 0) {
          this.$message.error("分数范围为0-10");
          this.ChangeClose();
          return;
        }
      }
      const { data: res } = await this.$http.post(
        "http://180.76.111.200:3001/api/oumu/DaFen",
        {
          student_id: stu_id,
          fraction_p1: val1,
          fraction_p2: val2,
        }
      );
      //console.log(res);
      if (res.code == 200) {
        this.$message.success("评分成功！");
        this.chaxun();
      } else {
        this.$message.error("评分失败！");
        this.ChangeClose();
      }
    },
    // 得到年级
    async getGrade() {
      const { data: res } = await this.$http.post(
        "http://180.76.111.200:6657/api/selectzhuanye"
      );
      for (var i = 0; i < res.data.length; i++) {
        this.optionss.push(res.data[i]);
      }
    },
    // 得到班级
    async getClass() {
      var specialzed = this.form.student_year;
      // 得到年级
      // console.log(this.form.student_year)
      if (this.form.student_year === "") {
        this.$message.error("数据错误");
      }
      const { data: res } = await this.$http.post(
        "http://180.76.111.200:6657/api/selectbanji",
        {
          specialzed: specialzed,
        }
      );
      // console.log(res.data);
      this.options2 = [];
      this.form.student_class = "";
      this.form.experiment_name = "";
      for (var i = 0; i < res.data.length; i++) {
        //console.log(res.data[i].class);
        this.options2.push(res.data[i]);
      }
    },
    // 得到实验名称
    async getEXper_Name() {
      const { data: res } = await this.$http.post(
        "http://180.76.111.200:6657/api/selectshiyan"
      );
      for (var i = 0; i < res.data.length; i++) {
        this.options1.push(res.data[i]);
      }
    },
    handleSizeChange(val) {
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
    },
    renderHeader(h) {
      return (
        <div>
          <el-button
            type="primary"
            size="mini"
            on-click={() => this.exportExcel()}
          >
            批量导出已完成实验
          </el-button>
        </div>
      );
    },
    // 批量导出
    async exportExcel() {
      //console.log(this.tableData);
      //console.log(this.form);
      this.loading = true;
      this.$message.success(
        "正在批量下载，请勿操作页面（此过程耗时大约两分钟）"
      );
      const mark = this.tableData.length;
      const arrID = [];
      var fileUrl = {};
      for (let i = 0; i < mark; i++) {
        // if (this.tableData[i].postate == 2 || this.tableData[i].state == 2 || this.tableData[i].state_danbai == 2) {
        //   if (this.form.experiment_name == "欧姆表的改装设计") {
        //     fileUrl = {
        //       fileUrl:
        //         "http://180.76.111.200:3001/api/oumu/oumupdf?student_id=" +
        //         this.tableData[i].student_num,
        //       renameFileName:
        //         this.tableData[i].student_class +
        //         "-" +
        //         this.tableData[i].student_name +
        //         "-" +
        //         this.tableData[i].experiment_name +
        //         ".pdf",
        //     };
        //     arrID.push(fileUrl);
        //   } else if (this.form.experiment_name == "霍尔效应测量磁感应强度") {
        //     fileUrl = {
        //       fileUrl:
        //         "http://180.76.111.200:3001/api/huoer/huoerpdf?student_id=" +
        //         this.tableData[i].student_num,
        //       renameFileName:
        //         this.tableData[i].student_class +
        //         "-" +
        //         this.tableData[i].student_name +
        //         "-" +
        //         this.tableData[i].experiment_name +
        //         ".pdf",
        //     };
        //     arrID.push(fileUrl);
        //   } else if (this.form.experiment_name == "单摆法测重力加速度") {
        //     fileUrl = {
        //       fileUrl:
        //         "http://180.76.111.200:3001/api/pdf?student_id=" + this.tableData[i].student_num,
        //       renameFileName:
        //         this.tableData[i].student_class + "-" + this.tableData[i].student_name + "-" + this.tableData[i].experiment + ".pdf",
        //     };
        //     arrID.push(fileUrl);
        //   } else if (this.form.experiment_name == "实验误差与数据处理") {
        //     fileUrl = {
        //       fileUrl:
        //         "http://180.76.111.200:3001/api/show/pdf1?student_id=" +this.tableData[i].student_num,
        //       renameFileName:
        //         this.tableData[i].student_class + "-" + this.tableData[i].student_name + "-" + this.tableData[i].experiment + ".pdf",
        //     };
        //     arrID.push(fileUrl);
        //   }
        // } else if (this.tableData[i].postate == 1) {
        //   this.$message.error("请先批阅再导出！");
        //   return;
        // } else if (this.tableData[i].postate == 0 && this.tableData[i].state == 2) {
        //   if (this.form.experiment_name == "劈尖测细丝实验") {
        //     fileUrl = {
        //       fileUrl:
        //         "http://120.55.71.155/api/experiment/pdf?student_id=" +
        //         this.tableData[i].student_num,
        //       renameFileName:
        //         this.tableData[i].student_class +
        //         "-" +
        //         this.tableData[i].student_name +
        //         "-" +
        //         this.tableData[i].experiment_name +
        //         ".pdf",
        //     };
        //     arrID.push(fileUrl);
        //   } else if (this.form.experiment_name == "电表的改装设计") {
        //     fileUrl = {
        //       fileUrl:
        //         "http://180.76.111.200:3001/api/dianbiao/dianbiaopdf?student_id=" +
        //         this.tableData[i].student_num,
        //       renameFileName:
        //         this.tableData[i].student_class +
        //         "-" +
        //         this.tableData[i].student_name +
        //         "-" +
        //         this.tableData[i].experiment_name +
        //         ".pdf",
        //     };
        //     arrID.push(fileUrl);
        //   }
        //   if (this.form.experiment_name == "箱式直流电桥测量电阻") {
        //     fileUrl = {
        //       fileUrl:
        //         "http://180.76.111.200:3001/api/xiangshi/xiangshipdf?student_id=" +
        //         this.tableData[i].student_num,
        //       renameFileName:
        //         this.tableData[i].student_class +
        //         "-" +
        //         this.tableData[i].student_name +
        //         "-" +
        //         this.tableData[i].experiment_name +
        //         ".pdf",
        //     };
        //     arrID.push(fileUrl);
        //   } else if (this.form.experiment_name == "大学物理实验一报告") {
        //     fileUrl = {
        //       fileUrl:
        //         "http://180.76.111.200/api/experiment1/pdf1?student_id=" +
        //         this.tableData[i].student_num,
        //       renameFileName:
        //         this.tableData[i].student_class +
        //         "-" +
        //         this.tableData[i].student_name +
        //         "-" +
        //         this.tableData[i].experiment_name +
        //         ".pdf",
        //     };
        //     arrID.push(fileUrl);
        //   } else if (this.form.experiment_name == "单摆法测重力加速度2") {
        //     fileUrl = {
        //       fileUrl:
        //         "http://180.76.111.200/api/completion15/pdf15?student_id=" +
        //         this.tableData[i].student_num,
        //       renameFileName:
        //         this.tableData[i].student_class +
        //         "-" +
        //         this.tableData[i].student_name +
        //         "-" +
        //         this.tableData[i].experiment_name +
        //         ".pdf",
        //     };
        //     arrID.push(fileUrl);
        //   }
        //   // else if (this.form.experiment_name == "牛顿环法测曲率半径") {
        //   //   fileUrl = {
        //   //     fileUrl:
        //   //       "http://120.55.71.155/api/experiment4/pdf4?student_id=" +
        //   //       this.tableData[i].student_num,
        //   //     renameFileName:
        //   //       this.tableData[i].student_class +
        //   //       "-" +
        //   //       this.tableData[i].student_name +
        //   //       "-" +
        //   //       this.tableData[i].experiment_name +
        //   //       ".pdf",
        //   //   };
        //   //   arrID.push(fileUrl);
        //   // }
        //   else if (this.form.experiment_name == "自组式直流电桥测量电阻值") {
        //     fileUrl = {
        //       fileUrl:
        //         "http://180.76.111.200/api/bridge1/pdf5?student_id=" +
        //         this.tableData[i].student_num,
        //       renameFileName:
        //         this.tableData[i].student_class +
        //         "-" +
        //         this.tableData[i].student_name +
        //         "-" +
        //         this.tableData[i].experiment_name +
        //         ".pdf",
        //     };
        //     arrID.push(fileUrl);
        //   } else if (this.form.experiment_name == "示波器的调整与使用") {
        //     fileUrl = {
        //       fileUrl:
        //         "http://180.76.111.200:3001/api/shiboqi/shiboqipdf?student_id=" +
        //         this.tableData[i].student_num,
        //       renameFileName:
        //         this.tableData[i].student_class +
        //         "-" +
        //         this.tableData[i].student_name +
        //         "-" +
        //         this.tableData[i].experiment_name +
        //         ".pdf",
        //     };
        //     arrID.push(fileUrl);
        //   } else if (this.form.experiment_name == "万用表改装设计实验") {
        //     fileUrl = {
        //       fileUrl:
        //         "http://180.76.111.200:3001/api/wanyongbiao/wanyongbiaopdf?student_id=" +
        //         this.tableData[i].student_num,
        //       renameFileName:
        //         this.tableData[i].student_class +
        //         "-" +
        //         this.tableData[i].student_name +
        //         "-" +
        //         this.tableData[i].experiment_name +
        //         ".pdf",
        //     };
        //     arrID.push(fileUrl);
        //   }
        // }

        // 新-2022/9/3
        if (this.form.experiment_name == "欧姆表的改装设计") {
          fileUrl = {
            fileUrl:
              "http://180.76.111.200:3001/api/oumu/oumupdf?student_id=" +
              this.tableData[i].student_num,
            renameFileName:
              this.tableData[i].student_class +
              "-" +
              this.tableData[i].student_name +
              "-" +
              this.tableData[i].experiment +
              ".pdf",
          };
          arrID.push(fileUrl);
        } else if (this.form.experiment_name == "霍尔效应测量磁感应强度") {
          fileUrl = {
            fileUrl:
              "http://180.76.111.200:3001/api/huoer/huoerpdf?student_id=" +
              this.tableData[i].student_num,
            renameFileName:
              this.tableData[i].student_class +
              "-" +
              this.tableData[i].student_name +
              "-" +
              this.tableData[i].experiment +
              ".pdf",
          };
          arrID.push(fileUrl);
        } else if (this.form.experiment_name == "单摆法测重力加速度") {
          fileUrl = {
            fileUrl:
              "http://180.76.111.200:3001/api/danbai2pdf?student_id=" +
              this.tableData[i].student_num,
            renameFileName:
              this.tableData[i].student_class +
              "-" +
              this.tableData[i].student_name +
              "-" +
              this.tableData[i].experiment +
              ".pdf",
          };
          arrID.push(fileUrl);
        } else if (this.form.experiment_name == "实验误差与数据处理") {
          fileUrl = {
            fileUrl:
              "http://180.76.111.200:3001/api/show/pdf1?student_id=" +
              this.tableData[i].student_num,
            renameFileName:
              this.tableData[i].student_class +
              "-" +
              this.tableData[i].student_name +
              "-" +
              this.tableData[i].experiment +
              ".pdf",
          };
          arrID.push(fileUrl);
        }
        if (this.form.experiment_name == "劈尖测细丝实验") {
          fileUrl = {
            fileUrl:
              "http://120.55.71.155/api/experiment/pdf?student_id=" +
              this.tableData[i].student_num,
            renameFileName:
              this.tableData[i].student_class +
              "-" +
              this.tableData[i].student_name +
              "-" +
              this.tableData[i].experiment +
              ".pdf",
          };
          arrID.push(fileUrl);
        } else if (this.form.experiment_name == "电表的改装设计") {
          fileUrl = {
            fileUrl:
              "http://180.76.111.200:3001/api/dianbiao/dianbiaopdf?student_id=" +
              this.tableData[i].student_num,
            renameFileName:
              this.tableData[i].student_class +
              "-" +
              this.tableData[i].student_name +
              "-" +
              this.tableData[i].experiment +
              ".pdf",
          };
          arrID.push(fileUrl);
        }
        if (this.form.experiment_name == "箱式直流电桥测量电阻") {
          fileUrl = {
            fileUrl:
              "http://180.76.111.200:3001/api/xiangshi/xiangshipdf?student_id=" +
              this.tableData[i].student_num,
            renameFileName:
              this.tableData[i].student_class +
              "-" +
              this.tableData[i].student_name +
              "-" +
              this.tableData[i].experiment +
              ".pdf",
          };
          arrID.push(fileUrl);
        } else if (this.form.experiment_name == "大学物理实验一报告") {
          fileUrl = {
            fileUrl:
              "http://180.76.111.200/api/experiment1/pdf1?student_id=" +
              this.tableData[i].student_num,
            renameFileName:
              this.tableData[i].student_class +
              "-" +
              this.tableData[i].student_name +
              "-" +
              this.tableData[i].experiment +
              ".pdf",
          };
          arrID.push(fileUrl);
        } else if (this.form.experiment_name == "单摆法测重力加速度") {
          fileUrl = {
            fileUrl:
              "http://180.76.111.200:3001/api/danbai2pdf?student_id=" +
              this.tableData[i].student_num,
            renameFileName:
              this.tableData[i].student_class +
              "-" +
              this.tableData[i].student_name +
              "-" +
              this.tableData[i].experiment +
              ".pdf",
          };
          arrID.push(fileUrl);
        } else if (this.form.experiment_name == "自组式直流电桥测量电阻值") {
          fileUrl = {
            fileUrl:
              "http://180.76.111.200:3001/api/zizu/zizupdf?student_id=" +
              this.tableData[i].student_num,
            renameFileName:
              this.tableData[i].student_class +
              "-" +
              this.tableData[i].student_name +
              "-" +
              this.tableData[i].experiment +
              ".pdf",
          };
          arrID.push(fileUrl);
        } else if (this.form.experiment_name == "示波器的调整与使用") {
          fileUrl = {
            fileUrl:
              "http://180.76.111.200:3001/api/shiboqi/shiboqipdf?student_id=" +
              this.tableData[i].student_num,
            renameFileName:
              this.tableData[i].student_class +
              "-" +
              this.tableData[i].student_name +
              "-" +
              this.tableData[i].experiment +
              ".pdf",
          };
          arrID.push(fileUrl);
        } else if (this.form.experiment_name == "万用表的改装设计") {
          fileUrl = {
            fileUrl:
              "http://180.76.111.200:3001/api/wanyongbiao/wanyongbiaopdf?student_id=" +
              this.tableData[i].student_num,
            renameFileName:
              this.tableData[i].student_class +
              "-" +
              this.tableData[i].student_name +
              "-" +
              this.tableData[i].experiment +
              ".pdf",
          };

          arrID.push(fileUrl);
        }
      }
      this.filesToRar(arrID, "file");
      setTimeout(() => {
        this.arrID = "";
      }, 2000);
    },
    // 导出全部pdf
    // async alles() {
    //   this.loading = true;
    //   this.$message.success(
    //     "正在批量下载，请勿操作页面（此过程耗时大约两分钟）"
    //   );
    //   const { data: res } = await this.$http.get(
    //     "http://180.76.111.200/api/findall"
    //   );
    //   // //console.log(res.data.length);
    //   const mark = res.data.length;
    //   const arrID = [];
    //   var fileUrl = {};
    //   //console.log(this.form.student_class);
    //   for (let i = 0; i < mark; i++) {
    //     if (res.data[i].student_class == this.form.student_class) {
    //       if (res.data[i].experiment_name == "欧姆表的改装设计") {
    //         fileUrl = {
    //           fileUrl:
    //             "http://180.76.111.200/api/experiment6/pdf6?student_id=" +
    //             res.data[i].id,
    //           renameFileName:
    //             res.data[i].student_class +
    //             "-" +
    //             res.data[i].student_name +
    //             "-" +
    //             res.data[i].experiment_name +
    //             ".pdf",
    //         };
    //         arrID.push(fileUrl);
    //       }
    //       if (res.data[i].experiment_name == "霍尔效应测量磁感应强度") {
    //         fileUrl = {
    //           fileUrl:
    //             "http://180.76.111.200/api/experiment9/pdf9?student_id=" +
    //             res.data[i].id,
    //           renameFileName:
    //             res.data[i].student_class +
    //             "-" +
    //             res.data[i].student_name +
    //             "-" +
    //             res.data[i].experiment_name +
    //             ".pdf",
    //         };
    //         arrID.push(fileUrl);
    //       }
    //       if (res.data[i].experiment_name == "电表的改装设计") {
    //         fileUrl = {
    //           fileUrl:
    //             "http://180.76.111.200/api/experiment10/pdf10?student_id=" +
    //             res.data[i].id,
    //           renameFileName:
    //             res.data[i].student_class +
    //             "-" +
    //             res.data[i].student_name +
    //             "-" +
    //             res.data[i].experiment_name +
    //             ".pdf",
    //         };
    //         arrID.push(fileUrl);
    //       }
    //       if (res.data[i].experiment_name == "箱式直流电桥测量电阻") {
    //         fileUrl = {
    //           fileUrl:
    //             "http://180.76.111.200/api/bridge/pdf?student_id=" +
    //             res.data[i].id,
    //           renameFileName:
    //             res.data[i].student_class +
    //             "-" +
    //             res.data[i].student_name +
    //             "-" +
    //             res.data[i].experiment_name +
    //             ".pdf",
    //         };
    //         arrID.push(fileUrl);
    //       }
    //       if (res.data[i].experiment_name == "大学物理实验一报告") {
    //         fileUrl = {
    //           fileUrl:
    //             "http://180.76.111.200/api/experiment1/pdf1?student_id=" +
    //             res.data[i].id,
    //           renameFileName:
    //             res.data[i].student_class +
    //             "-" +
    //             res.data[i].student_name +
    //             "-" +
    //             res.data[i].experiment_name +
    //             ".pdf",
    //         };
    //         arrID.push(fileUrl);
    //       }
    //       if (res.data[i].experiment_name == "单摆法测重力加速度") {
    //         fileUrl = {
    //           fileUrl:
    //             "http://180.76.111.200/api/pendulum/pdf3?student_id=" +
    //             res.data[i].id,
    //           renameFileName:
    //             res.data[i].student_class +
    //             "-" +
    //             res.data[i].student_name +
    //             "-" +
    //             res.data[i].experiment_name +
    //             ".pdf",
    //         };
    //         arrID.push(fileUrl);
    //       }
    //       if (res.data[i].experiment_name == "单摆法测重力加速度2") {
    //         fileUrl = {
    //           fileUrl:
    //             "http://180.76.111.200/api/completion15/pdf15?student_id=" +
    //             res.data[i].id,
    //           renameFileName:
    //             res.data[i].student_class +
    //             "-" +
    //             res.data[i].student_name +
    //             "-" +
    //             res.data[i].experiment_name +
    //             ".pdf",
    //         };
    //         arrID.push(fileUrl);
    //       }
    //       if (res.data[i].experiment_name == "自组式直流电桥测量电阻值") {
    //         fileUrl = {
    //           fileUrl:
    //             "http://180.76.111.200/api/bridge1/pdf5?student_id=" +
    //             res.data[i].id,
    //           renameFileName:
    //             res.data[i].student_class +
    //             "-" +
    //             res.data[i].student_name +
    //             "-" +
    //             res.data[i].experiment_name +
    //             ".pdf",
    //         };
    //         arrID.push(fileUrl);
    //       }
    //       if (res.data[i].experiment_name == "示波器的调整与使用") {
    //         fileUrl = {
    //           fileUrl:
    //             "http://180.76.111.200/api/experiment14/pdf14?student_id=" +
    //             res.data[i].id,
    //           renameFileName:
    //             res.data[i].student_class +
    //             "-" +
    //             res.data[i].student_name +
    //             "-" +
    //             res.data[i].experiment_name +
    //             ".pdf",
    //         };
    //         arrID.push(fileUrl);
    //       }
    //       if (res.data[i].experiment_name == "万用表改装设计实验") {
    //         fileUrl = {
    //           fileUrl:
    //             "http://180.76.111.200/api/experiment11/pdf11?student_id=" +
    //             res.data[i].id,
    //           renameFileName:
    //             res.data[i].student_class +
    //             "-" +
    //             res.data[i].student_name +
    //             "-" +
    //             res.data[i].experiment_name +
    //             ".pdf",
    //         };
    //         arrID.push(fileUrl);
    //       }
    //     }
    //   }
    //   //console.log(arrID);

    //   this.filesToRar(arrID, "file");
    //   //console.log(this.filesToRar);
    //   setTimeout(() => {
    //     this.arrID = "";
    //   }, 2000);
    // },
    // 查询-旧
    // async chaxun() {
    //   var that = this;
    //   if (this.form.experiment_name == "单摆法测重力加速度") {
    //     this.form.experiment_name = "单摆法测重力加速度2";
    //   }
    //   // //console.log(this.form.experiment_name);
    //   const { data: res } = await this.$http.get(
    //     "/api/admin/home?student_year=" +
    //     this.form.student_year +
    //     "&&student_class=" +
    //     this.form.student_class +
    //     "&&experiment_name=" +
    //     this.form.experiment_name
    //   );
    //   // //console.log(res);
    //   if (res.code == 200) {
    //     this.$message.success("查询成功");
    //     that.tableData = res.data;
    //   } else {
    //     this.$message.error(res.msg);
    //   }
    // },

    // 查询-新
    async chaxun() {
      var year = this.form.student_year;
      var new_class = this.form.student_class;
      var experiment = this.form.experiment_name;
      if (year === "" || new_class === "" || experiment === "") {
        this.$message.error("格式错误，请重新填写相关信息");
        return;
      }
      // if (this.form.experiment_name == "单摆法测重力加速度") {
      //   this.form.experiment_name = "单摆法测重力加速度2";
      // }
      const { data: res } = await this.$http.post(
        "http://180.76.111.200:3001/api/show/showxxallin",
        { year: year, class: new_class, experiment: experiment }
      );
      // //console.log(res);
      if (res.code == 200) {
        if (res.data.length === 0) {
          this.$message.error("数据为空");
          return;
        }
        this.$message.success("查询成功");
        // //console.log(res);
        this.tableData = res.data;
      } else {
        this.$message.error(res.msg);
      }
    },

    // 主观题打分

    // 批阅
    async dialog(id) {
      this.dialogVisible = true;
      this.student_id = id;
      if (this.form.experiment_name == "霍尔效应测量磁感应强度") {
        const { data: res } = await this.$http.get(
          "api/experiment9/returnphoto?student_id=" + id
        );
        // //console.log(res);
        if (res.code == 200) {
          this.form.p1 = res.data[0].tu;
          // this.form.p2 = res.data.p2;
        }
      }
      // //console.log(id);

      if (this.form.experiment_name == "欧姆表的改装设计") {
        const { data: res } = await this.$http.post(
          "/api/experiment6/completion6out",
          {
            student_id: id,
          }
        );
        // //console.log(res);
        if (res.code == 200) {
          this.form.p1 = res.data.p1;
          this.form.p2 = res.data.p2;
          // //console.log(this.form.p1);
          // //console.log(this.form.p2);
        }
        if (res.code == 100) {
          this.dialogVisible = false;
          this.$message.error("查询失败");
        }
      }
    },
    dialogs() {
      this.dialogVisible = false;
    },
    // 提交分数
    async dialogs1() {
      if (this.form.experiment_name == "欧姆表的改装设计") {
        // //console.log(123);
        if (
          this.form.fraction_p1 != "" &&
          this.form.fraction_p1 >= 0 &&
          this.form.fraction_p1 <= 5 &&
          this.form.fraction_p2 != "" &&
          this.form.fraction_p2 >= 0 &&
          this.form.fraction_p2 <= 5
        ) {
          // //console.log(456);
          // //console.log(this.form.fraction_p1);
          // //console.log(this.form.fraction_p2);
          const { data: res } = await this.$http.post(
            "/api/oumu/DaFen?student_id=" +
              this.student_id +
              "&&fraction_p1=" +
              this.form.fraction_p1 +
              "&&fraction_p2=" +
              this.form.fraction_p2
          );
          if (res.code == 200) {
            // //console.log(res);
            this.chaxun();
          }
          this.dialogVisible = false;
        } else {
          this.$message({
            type: "error",
            message: "请输入分数",
          });
        }
      }
      if (this.form.experiment_name == "霍尔效应测量磁感应强度") {
        if (
          this.form.fraction_p1 != "" &&
          this.form.fraction_p1 >= 0 &&
          this.form.fraction_p1 <= 20
        ) {
          const { data: res } = await this.$http.post(
            "/api/huoer/DaFen?student_id=" +
              this.student_id +
              "&&fraction=" +
              this.form.fraction_p1
            // +
            // "&&fraction_p2=" +
            // this.form.fraction_p2
          );
          if (res.code == 200) {
            this.chaxun();
          }
          this.dialogVisible = false;
        } else {
          this.$message({
            type: "error",
            message: "请输入分数",
          });
        }
      }
    },
    // 导出pdf
    async daochu(val) {
      // //console.log(val);
      var student_id = val.student_num;
      if (this.form.experiment_name == "欧姆表的改装设计") {
        window.location.href =
          "http://180.76.111.200:3001/api/oumu/oumupdf?student_id=" +
          student_id;
      } else if (this.form.experiment_name == "劈尖测细丝实验") {
        window.location.href =
          "http://180.76.111.200/api/experiment/pdf?student_id=" + student_id;
      } else if (this.form.experiment_name == "电表的改装设计") {
        window.location.href =
          "http://180.76.111.200:3001/api/dianbiao/dianbiaopdf?student_id=" +
          student_id;
      } else if (this.form.experiment_name == "万用表的改装设计") {
        window.location.href =
          "http://180.76.111.200:3001/api/wanyongbiao/wanyongbiaopdf?student_id=" +
          student_id;
      } else if (this.form.experiment_name == "箱式直流电桥测量电阻") {
        window.location.href =
          "http://180.76.111.200:3001/api/xiangshi/xiangshipdf?student_id=" +
          student_id;
      } else if (this.form.experiment_name == "大学物理实验一报告") {
        window.location.href =
          "http://180.76.111.200:3001/api/experiment1/pdf1?student_id=" +
          student_id;
      }
      // else if (this.form.experiment_name == "单摆法测重力加速度2") {
      //   window.location.href =
      //     "http://180.76.111.200:3001/api/danbai2pdf?student_id=" +
      //     student_id;
      // }
      else if (this.form.experiment_name == "牛顿环法测曲率半径") {
        window.location.href =
          "http://180.76.111.200:3001/api/experiment4/pdf4?student_id=" +
          student_id;
      } else if (this.form.experiment_name == "欧姆表的改装设计") {
        window.location.href =
          "http://180.76.111.200:3001/api/oumu/oumupdf?student_id=" +
          student_id;
      } else if (this.form.experiment_name == "自组式直流电桥测量电阻值") {
        window.location.href =
          "http://180.76.111.200:3001/api/zizu/zizupdf?student_id=" +
          student_id;
      } else if (this.form.experiment_name == "示波器的调整与使用") {
        window.location.href =
          "http://180.76.111.200:3001/api/shiboqi/shiboqipdf?student_id=" +
          student_id;
      } else if (this.form.experiment_name == "霍尔效应测量磁感应强度") {
        window.location.href =
          "http://180.76.111.200:3001/api/huoer/huoerpdf?student_id=" +
          student_id;
      } else if (this.form.experiment_name == "单摆法测重力加速度") {
        window.location.href =
          "http://180.76.111.200:3001/api/danbainewpdf?student_id=" +
          student_id;
      } else if (this.form.experiment_name == "旧单摆法测重力加速度") {
        window.location.href =
          "http://180.76.111.200:3001/api/danbai2pdf?student_id=" + student_id;
      } else if (this.form.experiment_name == "实验误差与数据处理") {
        window.location.href =
          "http://180.76.111.200:3001/api/show/pdf1?student_id=" + student_id;
      }
    },
    //文件打包
    // async filesToRar(arrImages, filename) {
    //   let _this = this;
    //   let zip = new JSZip();
    //   let cache = {};
    //   let promises = [];
    //   _this.title = "正在加载压缩文件";
    //   for (let item of arrImages) {
    //     var promise = _this.getImgArrayBuffer(item.fileUrl).then((data) => {
    //       // 下载文件, 并存成ArrayBuffer对象(blob)
    //       zip.file(item.renameFileName, data, { binary: true }); // 逐个添加文件
    //       cache[item.renameFileName] = data;
    //     });
    //     promises.push(promise);
    //   }
    //   Promise.all(promises)
    //     .then(() => {
    //       zip.generateAsync({ type: "blob" }).then((content) => {
    //         _this.title = "正在压缩";
    //         // 生成二进制流
    //         FileSaver.saveAs(content, filename); // 利用file-saver保存文件 自定义文件名
    //         _this.title = "压缩完成";
    //       });
    //     })
    //     .catch((res) => {
    //       _this.$message.error("文件压缩失败");
    //     });
    // },
    //获取文件blob
    // getImgArrayBuffer(url) {
    //   let _this = this;
    //   return new Promise((resolve, reject) => {
    //     //通过请求获取文件blob格式
    //     let xmlhttp = new XMLHttpRequest();
    //     xmlhttp.open("GET", url, true);
    //     xmlhttp.responseType = "blob";
    //     xmlhttp.onload = function () {
    //       if (this.status == 200) {
    //         resolve(this.response);
    //       } else {
    //         reject(this.status);
    //       }
    //     };
    //     xmlhttp.send();
    //   });
    // },
    // 导出Excel

    //文件打包
    async filesToRar(arrImages, filename) {
      let _this = this;
      let zip = new JSZip();
      let cache = {};
      let promises = [];
      for (let item of arrImages) {
        var promise = _this.getImgArrayBuffer(item.fileUrl).then((data) => {
          // 下载文件, 并存成ArrayBuffer对象(blob)
          if (data !== 0) {
            zip.file(item.renameFileName, data, { binary: true }); // 逐个添加文件
            cache[item.renameFileName] = data;
          }
        });
        promises.push(promise);
      }
      Promise.all(promises)
        .then(() => {
          zip.generateAsync({ type: "blob" }).then((content) => {
            // 生成二进制流
            FileSaver.saveAs(content, filename); // 利用file-saver保存文件 自定义文件名
            _this.$message.success("压缩完成");
            _this.loading = false;
          });
        })
        .catch((res) => {
          _this.$message.error("文件压缩失败");
        });
    },
    //获取文件blob
    async getImgArrayBuffer(url) {
      try {
        const res = await axios({ url, responseType: "blob" });
        if (res.status == 200) {
          return res.data;
        }
      } catch (err) {
        // //console.log(url);
        return 0;
      }
    },
    async excel() {
      //console.log(this.form.student_class);
      if (this.form.student_class == "") {
        this.$message.error("请选择班级！");
      } else {
        window.open(
          "http://180.76.111.200:3001/api/export?student_class=" +
            this.form.student_class
        );
      }
    },
  },
};
</script>

<style scoped>
textarea {
  width: 80%;
  height: 150px;
  margin-bottom: 2%;
}
.el-input {
  width: 120px;
  margin-bottom: 2%;
}
.el-button {
  margin-bottom: 1%;
}

p {
  color: #8f8a8a;
}
.nav {
  background-color: #f0f0f0;
  height: 60px;
  min-width: 700px;
  /* line-height: 80px; */
  /* text-align: center; */
  border-radius: 15px;
  margin-top: 20px;
  display: flex;
  justify-content: space-around;
  align-content: center;
}
.el-cascader,
.el-select {
  /* display: flex;
    justify-content: space-around;
    align-content: center; */
  margin-top: 10px;
  width: 300px;
}
.block {
  width: 100%;
}
.tablr ::v-deep .el-table__body tr:hover > td {
  background-color: rgb(236, 236, 236) !important;
}
.header {
  /* float: right; */
  width: 400px;
  min-width: 300px;
}
.box-card {
  min-width: 800px;
}
.btn {
  margin-top: 10px;
  width: 60px;
  height: 40px;
  display: flex;
  justify-content: center;
}
.btns {
  margin-top: 10px;
  width: 80px;
  height: 40px;
  display: flex;
  justify-content: center;
}
/* .toutou{
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding: 20px ;
} */
.photo {
  /* overflow: auto; */
  width: 80%;
  margin: 0 auto;
  height: 300px;
}
.photo1 {
  /* overflow: auto; */
  width: 80%;
  margin: 0 auto;
  margin-top: 94px;
  height: 300px;
}
.photos {
  /* overflow: auto; */
  width: 100%;
  height: 100%;
}
.tupian2 {
  margin-top: 30px;
}
.el-dialog .mark_input {
  width: 80%;
  height: 40px;
  margin-top: 43px;
  /* margin-bottom: 20px; */
  position: absolute;
  left: 10%;
  right: 10%;
}
.dialog-footer {
  width: 80%;
  margin: 15px auto;
  display: flex;
  justify-content: space-between;
  margin-top: 80px !important;
}
.nopiyue {
  display: none;
}
.piyue {
  display: block;
}
p {
  font-size: 15px;
}
.shurukuang {
  width: 625px;
  height: 50px;
}
</style>
